package admin.action.count.createFile;

import java.io.UnsupportedEncodingException;

import teacher.bean.Patent;
import tools.StringDate;
import admin.databaseToExcel.PullPatentToExcel;

public class PatentCreateAction {
	
	private Patent patent;
	private String applyDate2;
	private String empowerDate2;
	private int direction;
	
	public Patent getPatent() {
		return patent;
	}
	public void setPatent(Patent patent) {
		this.patent = patent;
	}
	public String getApplyDate2() {
		return applyDate2;
	}
	public void setApplyDate2(String applyDate2) {
		this.applyDate2 = applyDate2;
	}
	public String getEmpowerDate2() {
		return empowerDate2;
	}
	public void setEmpowerDate2(String empowerDate2) {
		this.empowerDate2 = empowerDate2;
	}
	
	public int getDirection() {
		return direction;
	}
	public void setDirection(int direction) {
		this.direction = direction;
	}

	public String execute()
	{
		
		if(this.getPatent()!=null)
		{
			if(this.getPatent().getName()==null||this.getPatent().getName().equals(""))
				this.getPatent().setName(null);
			else
			{
					try {
						this.getPatent().setName(new String(this.getPatent().getName().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPatent().getFiestInventor()==null||this.getPatent().getFiestInventor().equals(""))
				this.getPatent().setFiestInventor(null);
			else
			{

					try {
						this.getPatent().setFiestInventor(new String(this.getPatent().getFiestInventor().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPatent().getApplyNumber()==null||this.getPatent().getApplyNumber().equals(""))
				this.getPatent().setApplyNumber(null);
			else
			{
					try {
						this.getPatent().setApplyNumber(new String(this.getPatent().getApplyNumber().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPatent().getEmpowerNum()==null||this.getPatent().getEmpowerNum().equals(""))
				this.getPatent().setEmpowerNum(null);
			else
			{
					try {
						this.getPatent().setEmpowerNum(new String(this.getPatent().getEmpowerNum().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPatent().getEmpowerUnit()==null||this.getPatent().getEmpowerUnit().equals(""))
				this.getPatent().setEmpowerUnit(null);
			else
			{

					try {
						this.getPatent().setEmpowerUnit(new String(this.getPatent().getEmpowerUnit().getBytes("iso-8859-1"),"utf-8"));
					} catch (UnsupportedEncodingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
			if(this.getPatent().getEmpowerDate()!=null)
				this.getPatent().setEmpowerDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getPatent().getEmpowerDate())));
			if(this.getPatent().getApplyDate()!=null)
				this.getPatent().setApplyDate(
						StringDate.StringToDate(
								StringDate.DateToString(
										this.getPatent().getApplyDate())));
		}
		Patent pat=new Patent();
		if(this.getApplyDate2()!=null)
		pat.setApplyDate(StringDate.StringToDate(this.getApplyDate2()));
		if(this.getEmpowerDate2()!=null)
		pat.setEmpowerDate(StringDate.StringToDate(this.getEmpowerDate2()));
		PullPatentToExcel.patentExcel(3, this.getPatent(), pat,this.getDirection());
		return "succ";
	}

}
